package net.xiangcaowuyu.example1.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import net.xiangcaowuyu.example1.Status;
import net.xiangcaowuyu.example1.listener.UserAuditListener;

import javax.persistence.*;
import java.util.Set;

@Entity
@Table(name = "sys_user")
@Data
@Slf4j

@EntityListeners({UserAuditListener.class})
public class SysUser extends AbstractAuditable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long userId;

    @JoinColumn(name = "dept_id", referencedColumnName = "dept_id")
    @ManyToOne(cascade = CascadeType.ALL)
    private SysDept sysDept;

    private String userName;

    private String nickName;

    private String userType;

    private String email;

    @Column(name = "phonenumber")
    private String phoneNumber;

    private String sex;

    private String avatar;

    @JsonIgnore
    private String password;

    @Enumerated(EnumType.STRING)
    private Status status;

    private String delFlag;

    private String loginIp;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private java.sql.Timestamp loginDate;

    private String remark;

    private Long recycleCompanyId;

    private Long medicalInstitutionId;

    private Long ethnicity;

    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "sys_user_role",
            joinColumns = {@JoinColumn(name = "user_id")},
            inverseJoinColumns = {@JoinColumn(name = "role_id")})
    private Set<SysRole> sysRoles;

    @Version
    private Long version;

}
